package com.qf.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.qf.exceptions.MyErrorCode;

/**
 * created by 赵文韬 on 2022/3/17 9:29
 */
//对象有三个属性，并且忽略掉属性值为空的属性
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class R {
    private int code;
    private String msg;
    private Object data;
    //setOk不传参，那就什么属性都不返回
    public static R setOk(){
        return setOk(null);
    }
    //如果setOk穿一个对象，那就传成功的参数，加成功的字符串，加对象都赋值，通过静态的getR设置
    public static R setOk(Object data){
        return getR(MyErrorCode.SUCCESS,"成功" ,data );
    }
    //如果setError不传参，那就所有属性不赋值，
    public static R setError(){
        return setError(null);
    }
    public static R setError(Object data){
        return getR(MyErrorCode.FAIL,"失败" ,data );
    }
    //如果setError穿对象，那就所有属性都通过静态的getR设置方法设置
    public static R getR(int code,String mas,Object data){
        R r = new R();
        r.setCode(code);
        r.setMsg(mas);
        r.setData(data);
        return r;
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
